﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GtsServer.Model;
using GtsServer.DAL;
using System.Data;
using GtsServer.Common;

namespace GtsServer.Manage.Controller
{
    public class PrizeTaskReocrdCotroller
    {
        PrizeTaskReocrdDAL dal = new PrizeTaskReocrdDAL();
        public List<PrizeTaskReocrdShow> GetList(int UserID)
        {
            DataSet ds = dal.GetList(UserID);
            List<PrizeTaskReocrdShow> list = IListDataSet.DataSetToIList<PrizeTaskReocrdShow>(ds, 0).ToList();
            foreach (var item in list)
            {
                if (item.Stuas.Equals(Convert.ToInt32(EnumPrizeTaskRecordstate.未领取)))
                    item.PrizeTaskReocrdState = EnumPrizeTaskRecordstate.未领取.ToString();
                else if (item.Stuas.Equals(Convert.ToInt32(EnumPrizeTaskRecordstate.已领取)))
                    item.PrizeTaskReocrdState = EnumPrizeTaskRecordstate.已领取.ToString();
                else if (item.Stuas.Equals(Convert.ToInt32(EnumPrizeTaskRecordstate.丢弃)))
                    item.PrizeTaskReocrdState = EnumPrizeTaskRecordstate.丢弃.ToString();
            }
            return list;
        }
        public List<PrizeTaskReocrdShow> GetListByState(int state, string type, string value,string remark, int pageIndex, int pageSize, out int userID, out int count)
        {
            count = 0;
            userID = 0;
            DataSet ds = dal.GetListByState(state, type, value,remark, pageIndex, pageSize);
            List<PrizeTaskReocrdShow> list = IListDataSet.DataSetToIList<PrizeTaskReocrdShow>(ds, 0).ToList();

            count = Convert.ToInt32(ds.Tables[1].Rows[0]["count"]);

            if (!string.IsNullOrEmpty(value) && ds.Tables[2].Rows.Count > 0)
                userID = Convert.ToInt32(ds.Tables[2].Rows[0]["ID"]);
            foreach (var item in list)
            {
                //if(item.Id )
                if (item.Stuas.Equals(Convert.ToInt32(EnumPrizeTaskRecordstate.未领取)))
                    item.PrizeTaskReocrdState = EnumPrizeTaskRecordstate.未领取.ToString();
                else if (item.Stuas.Equals(Convert.ToInt32(EnumPrizeTaskRecordstate.已领取)))
                    item.PrizeTaskReocrdState = EnumPrizeTaskRecordstate.已领取.ToString();
                else if (item.Stuas.Equals(Convert.ToInt32(EnumPrizeTaskRecordstate.丢弃)))
                    item.PrizeTaskReocrdState = EnumPrizeTaskRecordstate.丢弃.ToString();
            }
            return list;
        }
        /// <summary>
        /// 增加方法
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        public int Add(PrizeTaskReocrd models)
        {
            return dal.Add(models);
        }
        /// <summary>
        /// 修改方法
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool Update(PrizeTaskReocrd model)
        {
            return dal.Update(model);
        }
        /// <summary>
        /// 删除方法
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public bool Delete(int ID)
        {
            return dal.Delete(ID);
        }
    }
}
